$().ready(function() {

});
var trimesterguideNavType = 0;
function trimesterguide(){
	html='';
	html+='<div class="wrapper-trimester-guide">';
		html+='<div class="trimesterguide-list"></div>';
	html+='</div>';	
	$('.box-two .title span').text("Trimester Guide");
	$('.box-two-content').html(html);
	get_trimestral_day();
	switchwindow('trimesterguide');
}
function trimesterguide_nav(){
	var chk_log = $.cookie('chk_log');	
	if(chk_log==1){
		html='';
		html+='<div class="wrapper-trimester-guide">';
			html+='<div class="trimesterguide-list"></div>';
		html+='</div>';	
		$('.box-two .title span').text("Trimester Guide");
		$('.box-two-content').html(html);		
		get_trimestral_day();
		switchwindow_no_animate('trimesterguide');
	}
}

function get_trimestral_day(){
	var ndays = 280;
	xfunc = "countdown/get_date";
	data_sent = {};
	
	$.ajax({ 
		type: "POST", // request type POST
		url: base_url+xfunc, // post to PHP file
		data: data_sent, // request send to PHP file
		dataType:'json',
		success: function(result){ // result = return from php request		
			var dateConceptionDate = $.cookie('dateConceptionDate');
			cdate = dateConceptionDate.split('-');
			
			nmonths = ndays/30.4166666667;// get 9 months
			nConceptionDate = new Date(cdate[0], cdate[1]-1,cdate[2]);// get date of conception
						
			var days = Math.round((new Date(result.yyyy, result.mm-1,result.dd)-nConceptionDate)/86400000); // now - start

			tmonths = days/30.4166666667;// get months
			tdays = (tmonths%1)/0.0328767123288;// get days
			
			tmonths = Math.floor(tmonths);
			tdays = Math.floor(tdays);	

			if(tdays>=0){
				tmonths+=1;
			}
			
			if(tmonths<=3){
				trimester = 1;
			} else if(tmonths<=6){
				trimester = 2;
			} else if(tmonths<=9){
				trimester = 3;
			} else {
				trimester = 4;
			}
			list_trimesterguide(trimester);
		}
	});	
}
function list_trimesterguide(trimester){
	var xfunc = 'trimesterguide/list_trimesterguide'
	html='';
	data_sent = {};
	
	$.ajax({ 
		type: "POST", // request type POST
		url: base_url+xfunc, // post to PHP file
		data: data_sent, // request send to PHP file
		dataType:'json',
		success: function(result){ // result = return from php request
			html='<ul>';
			$(result.strTitle).each(function(k,v){
				if(result.intCode[k]==trimester){
					html+='<li>';
						html+='<ul>';
							html+='<li onclick="trimesterguide_notes(\''+result.strNote[k]+'\',\''+result.strTitle[k]+'\');">';
								html+='<img src="'+base_url+'assets/uploaded/img/thumbnail/'+result.strImgLink[k]+'"';
							html+='</li>';
							html+='<li onclick="trimesterguide_notes(\''+result.strNote[k]+'\',\''+result.strTitle[k]+'\');">';
								html+=result.strTitle[k];
						html+='</li>';						
						html+='</ul>';
					html+='</li>';
				}
			});
			html+='</ul>';
			$('.trimesterguide-list').html(html);
		}
	});	
}
function trimesterguide_notes(notes,title){
	html='';
	html+='<div class="wrapper-trimester-guide-notes">';
		html+='<div class="trimesterguide-notes">';
			html+='<p></p>';	
		html+='</div>';	
	html+='</div>';	
	$('.box-two-content').html(html);

	$('.trimester-guide-box-notes>.title>span').html(title);
	$('.trimesterguide-notes>p').html(notes);
	html='<div class="back-btn-two pull-right" title="Trimester Guide"><a></a></div>';
	$('.box-two .title').append(html);
	$('.back-btn-two').click(function(){
		trimesterguide();
		$('.back-btn-two').remove();
	});		
}
